<!--
 * @Description: 任务下发弹窗
 * @Author: huacong
 * @Date: 2020-09-04 15:30:44
 * @LastEditTime: 2020-09-07 13:09:56
 * @LastEditors: huacong
-->
<template lang="pug">
  modal-form(
    title="待下发信息确认"
    :visible.sync="visibleDialog"
    :formItems="addItems"
    :submitting="submitting"
    :formSubmit="submitHandle"
    sureText="确认并下发"
    @close="$_handleCancel"
  )
    el-alert.mb16(show-icon :closable="false" type="info" slot="alert")
      p(slot="title")
        span.mr10
          | 抽查机构:
          span.c_primary {{orgName}}
        span
          | 抽查比例: 按照
          span.c_error.ml5.mr5 {{percent}}%
          | 比例查房
</template>
<script>
import { issue } from '@/api/remote'
import { ModalForm } from '@/components'
// import { formatTimestamp } from '@/utils/util'

export default {
  name: 'TaskDistributeModal',
  components: {
    ModalForm
  },
  props: {
    id: {
      type: [String, Number],
      default: '',
      required: true
    },
    orgName: {
      type: String,
      default: ''
    },
    percent: {
      type: [String, Number],
      default: ''
    },
    visible: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    visibleDialog: {
      get () {
        return this.visible
      },
      set (val) {
        this.$emit('update:visible', val)
      }
    },
    addItems () {
      return [
        {
          key: 'taskDura',
          label: '任务时长',
          type: 'selectdict',
          dictKey: 'SCEN_TASK_DURA',
          rules: { required: true, message: '请输入' }
        },
        {
          key: 'beginTime',
          label: '开始时间',
          type: 'datetime',
          formatFlag: true,
          rules: { required: true, message: '请输入' },
          initialValue: new Date()
        }
      ]
    }
  },
  data () {
    return {
      submitting: false
    }
  },
  methods: {
    submitHandle (vals) {
      console.log(vals)
      this.submitting = true
      issue({ ...vals, taskDura: parseFloat(this.dictFilter(vals.taskDura, 'SCEN_TASK_DURA')), taskId: this.id }).then(() => {
        this.$message.success('提交成功')
        this.$emit('getList')
        this.visibleDialog = false
      }).finally(() => {
        this.submitting = false
      })
    },
    $_handleCancel () {
      this.visibleDialog = false
    }
  }
}
</script>
